package com.gw2.gw2world;

import com.gw2.gw2world.controller.NavigationManager;
import com.gw2.gw2world.controller.Tools;
import com.gw2.gw2world.fragment.ActiveEventFragment;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.app.Activity;
import android.content.res.Configuration;

public class ActiveEventActivity extends Activity {
	@SuppressWarnings("unused")
	private static final String TAG = "ActiveEventActivity";
	private NavigationManager nm;
	private ActiveEventFragment aef;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Tools.forceLocale(this);
		setContentView(R.layout.active_events);
		nm=new NavigationManager(this, R.id.drawer_layout_ae, R.id.left_drawer_ae);
		aef=(ActiveEventFragment)getFragmentManager().findFragmentById(R.id.f_ae);
	}
	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.active_events, menu);
        return super.onCreateOptionsMenu(menu);
    }
	@Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // If the nav drawer is open, hide action items related to the content view
        //boolean drawerOpen = nm.isDrawerOpen();
        //menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
        return super.onPrepareOptionsMenu(menu);
    }
	@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Pass the event to ActionBarDrawerToggle, if it returns
        // true, then it has handled the app icon touch event
        if (nm.getDrawerToggle().onOptionsItemSelected(item)) {
          return true;
        }
        if(item.getItemId()==R.id.mi_ae_map) aef.selectMap();
        if(item.getItemId()==R.id.mi_ae_filter) aef.selectFilter();
		return super.onOptionsItemSelected(item);
	}
	@Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        nm.getDrawerToggle().syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // Pass any configuration change to the drawer toggles
        nm.getDrawerToggle().onConfigurationChanged(newConfig);
    }
}
